// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Data.Common;
using System.Data.Odbc;

namespace SnapObjects.Data.Odbc
{
    /// <summary>
    ///     Represents the entry to the SAP HANA database.
    /// </summary>
    public class OdbcHanaDataContext : DataContext
    {
        /// <summary>
        ///     Initializes a new instance of the OdbcHanaDataContext class by passing the OdbcHanaDataContextOptions type object as a parameter.
        /// </summary>
        /// <param name="dataContextOptions">
        ///     The options to be set for the DataContext object.
        /// </param>
        public OdbcHanaDataContext(IDataContextOptions dataContextOptions)
            : base(dataContextOptions)
        {
            this.AdoDbProviderFactory = new OdbcHanaAdoDbProviderFactory(this);
            this.AdoDbSqlProvider = new OdbcHanaAdoDbSqlProvider(this.ContextOptions);
            this.AdoDbSchemaProvider = new OdbcHanaAdoDbSchemaProvider(this);
        }

        /// <summary>
        ///     Initializes a new instance of the OdbcHanaDataContext class by passing the OdbcConnection type object as a parameter.
        /// </summary>
        /// <param name="dbConnection">
        ///     The connection object which is an OdbcConnection instance.
        /// </param>
        public OdbcHanaDataContext(OdbcConnection dbConnection)
            : base(dbConnection, new OdbcHanaDataContextOptions(String.Empty))
        {
            this.AdoDbProviderFactory = new OdbcHanaAdoDbProviderFactory(this);
            this.AdoDbSqlProvider = new OdbcHanaAdoDbSqlProvider(this.ContextOptions);
            this.AdoDbSchemaProvider = new OdbcHanaAdoDbSchemaProvider(this);
        }

        internal override IAdoDbProviderFactory AdoDbProviderFactory { get; }

        internal override IAdoDbSchemaProvider AdoDbSchemaProvider { get; }

        internal override IAdoDbSqlProvider AdoDbSqlProvider { get; }

        internal override IAdoDbConnection CreateAdoDbConnection(string connectionString)
        {
            return new OdbcHanaAdoDbConnection(connectionString, this.ContextOptions);
        }

        internal override IAdoDbConnection CreateAdoDbConnection(DbConnection dbConnection)
        {
            return new OdbcHanaAdoDbConnection((OdbcConnection)dbConnection, this.ContextOptions);
        }
    }
}
